﻿<%@ Page Title="" Language="C#" MasterPageFile="~/admin/admin.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="admin_resources_class_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="../../artcles/class/StyleSheet.css" rel="Stylesheet" />
<script type="text/javascript" src="../../../js/jquery-1.4.1.min.js" ></script>
<script type="text/javascript">
    var classlistxml;
    var classid;
    $(document).ready(function () {
        InitClassList();
        $("#addbtn").click(function () {
            if ($("#namebox").attr("value").trim() == "") {
                alert("分类名不能为空！");
                return false;
            }
            AddClass();
        });
        $("#editbtn").click(function () {
            UpdateClass();
        });
    });
    function InitClassList() {
        $("#listtable").toggle(600);
        var postdata={"act":"get"};
        $.ajax({
            url: "../../../Handles/resource/resclass.ashx",
            type: "POST",
            datatype: "xml",
            data: $.param(postdata),
            success: function (xml) {
                classlistxml = xml;
                $("#listbody").empty();
                $(xml).find("Table").each(function (v) {
                    var html = '<tr>';
                    html += '<td style="text-align:center">' + $(this).attr("ClassID") + '</td>';
                    html += '<td>' + $(this).children("ClassName").text() + '</td>';
                    html += '<td style="text-align:center">' + $(this).children("Descsript").text() + '</td>';
                    html += '<td style="text-align:center"><a href="#" class="listrow" tag="' + $(this).attr("ClassID") + '">编辑</a></td>';
                    $("#listbody").append(html);
                });
                $("#listtable").toggle(600);
                $(".listrow").click(function () {
                    var id = $(this).attr("tag");
                    $(classlistxml).find("Table").each(function () {
                        if ($(this).attr("ClassID") == id) {
                            classid = id;
                            $("#namebox").attr("value", $(this).children("ClassName").text());
                            $("#desbox").val($(this).children("Descsript").text());
                        }
                    });
                });
            }
        });
    }
    function AddClass() {
        var postdata = { "act": "add", "cname": $("#namebox").attr("value"), "des": $("#desbox").val() };
        $.ajax({
            url: "../../../Handles/resource/resclass.ashx",
            type: "POST",
            datatype: "xml",
            data: $.param(postdata),
            success: function (s) {
                if (s == 0) {
                    alert("添加失败");
                }
                InitClassList();
            }
        });
    }
    function DelClass() {
        if (classid !== undefined) {
            if (confirm("真的要删除吗？")) {
                var postdata = { "act": "del", "cid": classid };
                $.ajax({
                    url: "../../../Handles/resource/resclass.ashx",
                    type: "POST",
                    data: $.param(postdata),
                    success: function (s) {
                        if (s == "1") {
                            alert("删除成功!");
                            classid = undefined;
                            $("#namebox").attr("value", "");
                            $("#desbox").val("");
                            InitClassList();
                        }
                        else {
                            alert("删除失败!");
                        }
                    }
                });
            }
        }
        else {
            alert("还未选择！");
        }
    }
    function UpdateClass() {
        if (classid !== undefined) {
            var postdata = { "act": "edit", "cid": classid, "cname": $("#namebox").attr("value"), "des": $("#desbox").val() };
            $.ajax({
                url: "../../../Handles/resource/resclass.ashx",
                type: "POST",
                data: $.param(postdata),
                success: function (s) {
                    if (s == "1") {
                        alert("修改成功!");
                        classid = undefined;
                        $("#namebox").attr("value", "");
                        $("#desbox").val("");
                        InitClassList();
                    }
                    else {
                        alert("修改失败!");
                    }
                }
            });
        }
        else {
            alert("还未选择！");
        }
    }
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<h1>资源分类管理</h1>
    <br />
    <table id="listtable">
        <thead>
            <tr style="background-color:Gray">
                <td style="text-align:center;width:80px"> 分类ID</td>
                <td style="text-align:center;width:200px">分类名称</td>
                <td style="text-align:center;width:220px">分类描述</td>
                <td style="text-align:center;width:80px">操作</td>
            </tr>
        </thead>
        <tbody id="listbody">
            
        </tbody>
    </table>
    <br />

    <div id="editbox">
    <div id="editleft">
        <p>分类名称：
                <input type="text" class="cinput" style="width:225px;height:16px" id="namebox" /></p>
        <p>分类描述：<br />
                <textarea id="desbox" style="width:330px;height:70px" class="cinput"></textarea></p>
    </div>
    <div id="editright">
        <input type="button" class="bluebutton" id="editbtn" value="修改" /><br /><br />
        <input type="button" class="bluebutton" id="addbtn" value="添加" /><br /><br />
        <input type="button" class="bluebutton" id="delbtn" onclick="DelClass()" value="删除" />
            <input type="hidden" id="hID" name="suredel" />
    </div>
    </div>
</asp:Content>

